﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.LogEntries.ArmyDispersionLogEntry
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.LogEntries
{
  public class ArmyDispersionLogEntry : LogEntry, IEncyclopediaLog, IChatNotification, IWarLog
  {
    [SaveableField(30)]
    public readonly Army.ArmyDispersionReason DispersionReason;
    [SaveableField(31)]
    private readonly uint _notificationTextColor;
    [SaveableField(32)]
    private readonly bool _isVisibleNotification;
    [SaveableField(33)]
    private readonly CharacterObject _armyLeader;
    [SaveableField(34)]
    private readonly TextObject _encyclopediaLinkWithName;

    internal static void AutoGeneratedStaticCollectObjectsArmyDispersionLogEntry(
      object o,
      List<object> collectedObjects)
    {
      ((LogEntry) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this._armyLeader);
      collectedObjects.Add((object) this._encyclopediaLinkWithName);
    }

    internal static object AutoGeneratedGetMemberValueDispersionReason(object o)
    {
      return (object) ((ArmyDispersionLogEntry) o).DispersionReason;
    }

    internal static object AutoGeneratedGetMemberValue_notificationTextColor(object o)
    {
      return (object) ((ArmyDispersionLogEntry) o)._notificationTextColor;
    }

    internal static object AutoGeneratedGetMemberValue_isVisibleNotification(object o)
    {
      return (object) ((ArmyDispersionLogEntry) o)._isVisibleNotification;
    }

    internal static object AutoGeneratedGetMemberValue_armyLeader(object o)
    {
      return (object) ((ArmyDispersionLogEntry) o)._armyLeader;
    }

    internal static object AutoGeneratedGetMemberValue_encyclopediaLinkWithName(object o)
    {
      return (object) ((ArmyDispersionLogEntry) o)._encyclopediaLinkWithName;
    }

    public override CampaignTime KeepInHistoryTime => CampaignTime.Weeks(1f);

    public override ChatNotificationType NotificationType
    {
      get
      {
        return this.DiplomaticNotification((IFaction) (this._armyLeader.HeroObject?.Clan ?? (Clan) null), (IFaction) null);
      }
    }

    public bool IsVisibleNotification => this._isVisibleNotification;

    public ArmyDispersionLogEntry(Army army, Army.ArmyDispersionReason reason)
    {
      this._armyLeader = army.ArmyOwner.CharacterObject;
      this._encyclopediaLinkWithName = army.EncyclopediaLinkWithName;
      Kingdom kingdom = army.Kingdom;
      this._notificationTextColor = kingdom != null ? kingdom.LabelColor : 0U;
      this.DispersionReason = reason;
      this._isVisibleNotification = army.LeaderParty.MapFaction == Hero.MainHero.MapFaction && army.Parties.IndexOf(MobileParty.MainParty) >= 0;
    }

    public override string ToString() => this.GetEncyclopediaText().ToString();

    public bool IsRelatedToWar(StanceLink stance, out IFaction effector, out IFaction effected)
    {
      IFaction faction1 = stance.Faction1;
      IFaction faction2 = stance.Faction2;
      effector = this._armyLeader.HeroObject.MapFaction;
      effected = (IFaction) null;
      return this._armyLeader.HeroObject.MapFaction == faction1 || this._armyLeader.HeroObject.MapFaction == faction2;
    }

    public TextObject GetNotificationText() => this.GetEncyclopediaText();

    public bool IsVisibleInEncyclopediaPageOf<T>(T obj) where T : MBObjectBase
    {
      return this._armyLeader != null && (object) obj == this._armyLeader.HeroObject;
    }

    public TextObject GetEncyclopediaText()
    {
      TextObject encyclopediaText;
      switch (this.DispersionReason)
      {
        case Army.ArmyDispersionReason.Unknown:
          encyclopediaText = new TextObject("{=5CJOMH90}{ARMY} has been disbanded.");
          break;
        case Army.ArmyDispersionReason.DismissalRequestedWithInfluence:
          encyclopediaText = new TextObject("{=bAVZloaC}{ARMY} has been disbanded since dismissal is requested.");
          break;
        case Army.ArmyDispersionReason.NotEnoughParty:
          encyclopediaText = new TextObject("{=s2lKb22C}{ARMY} has been disbanded since other parties has left the army.");
          break;
        case Army.ArmyDispersionReason.KingdomChanged:
          encyclopediaText = new TextObject("{=6XAvdeEE}{ARMY} has been disbanded since kingdom has been changed.");
          break;
        case Army.ArmyDispersionReason.CohesionDepleted:
          encyclopediaText = new TextObject("{=ESM0NhLy}{ARMY} has been disbanded since cohesion has been depleted.");
          break;
        case Army.ArmyDispersionReason.ObjectiveFinished:
          encyclopediaText = new TextObject("{=6XRt8101}{ARMY} has been disbanded since the objective is finished");
          break;
        case Army.ArmyDispersionReason.LeaderPartyRemoved:
          encyclopediaText = new TextObject("{=A3HdRbqf}{ARMY} has been disbanded since the leader party has left the army.");
          break;
        case Army.ArmyDispersionReason.PlayerTakenPrisoner:
          encyclopediaText = new TextObject("{=loEI5awS}{ARMY} has been disbanded since the player has taken as a prisoner");
          break;
        case Army.ArmyDispersionReason.CannotElectNewLeader:
          encyclopediaText = new TextObject("{=7DCzgGNP}{ARMY} has been disbanded since a new leader cannot be selected");
          break;
        case Army.ArmyDispersionReason.LeaderCannotArrivePointOnTime:
          encyclopediaText = new TextObject("{=t5Y0gTGv}{ARMY} has been disbanded since the leader couldn't arrived to the point on time.");
          break;
        case Army.ArmyDispersionReason.ArmyLeaderIsDead:
          encyclopediaText = new TextObject("{=t6FNeiOC}{ARMY} has been disbanded since the army leader is dead.");
          break;
        default:
          encyclopediaText = new TextObject("{=5CJOMH90}{ARMY} has been disbanded.");
          break;
      }
      TextObject variable = new TextObject("{=nbmctMLk}{LEADER_NAME}{.o} Army");
      variable.SetTextVariable("LEADER_NAME", this._armyLeader.Name);
      encyclopediaText.SetTextVariable("ARMY", variable);
      return encyclopediaText;
    }
  }
}
